package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.ExternalFile;
import com.amsp.oa.oademo.service.ExternalFileService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "外来文件管理")
@RestController
@RequestMapping("/api/external-file")
public class ExternalFileController {

    @Autowired
    private ExternalFileService externalFileService;

    @ApiOperation("分页查询外来文件")
    @GetMapping("/page")
    public ResponseEntity<IPage<ExternalFile>> getPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String keyword) {
        return ResponseEntity.ok(externalFileService.getPage(current, size, keyword));
    }

    @ApiOperation("根据ID获取外来文件")
    @GetMapping("/{id}")
    public ResponseEntity<ExternalFile> getById(@PathVariable Long id) {
        return ResponseEntity.ok(externalFileService.getById(id));
    }

    @ApiOperation("批量保存或更新外来文件")
    @PostMapping("/batch")
    public ResponseEntity<Boolean> batchSaveOrUpdate(@RequestBody List<ExternalFile> fileList) {
        return ResponseEntity.ok(externalFileService.batchSaveOrUpdate(fileList));
    }

    @ApiOperation("删除外来文件")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable Long id) {
        return ResponseEntity.ok(externalFileService.removeById(id));
    }
}